<!--#include file="Ini.asp"-->
<!--#include file="../AspLib/Functions.asp"-->

<%
Response.expires = 0
MREGIAO=REQUEST("REGIAO")
MDIVUL=REQUEST("DIVUL")
MACAO=TRIM(REQUEST("ACAO"))
MREF=""
IF MREGIAO<>"" THEN
  MSQL="SELECT UF,SUM(QTD) AS QTD,EDITORA,SUM(VALOR) AS VALOR FROM PNLD_2005_EDITORA "
  MSQL=MSQL & " WHERE REGIAO IN ('" & REQUEST("REGIAO") & "')"
  MREF=MREF & " REGIAO: " & MREGIAO
  IF MDIVUL<>"" THEN
       MSQL=MSQL & " AND DIVULGADOR='" & MDIVUL & "'"
       MREF=MREF & " DIVULGADOR : " & MDIVUL
  END IF
  IF MACAO="PNLEM" THEN
       MSQL=MSQL & " AND TIPOOBJETO='" & MACAO & "'"
       MREF=MREF & " PNLEM "
  END IF
  MSQL=MSQL & " GROUP BY UF,EDITORA ORDER BY UF,VALOR DESC"
ELSE
  MSQL="SELECT '  ' AS UF,EDITORA,SUM(QTD) AS QTD,SUM(VALOR) AS VALOR "
  MSQL=MSQL & " FROM PNLD_2005_EDITORA "
  IF MACAO="PNLEM" THEN
       MSQL=MSQL & " WHERE TIPOOBJETO='" & MACAO & "'"
       MREF=MREF & " PNLEM "
  END IF
  MSQL=MSQL & " GROUP BY EDITORA ORDER BY VALOR DESC"
END IF

'RESPONSE.WRITE MSQL
'RESPONSE.END
Set Conn = Server.CreateObject("ADODB.Connection")
conn.CommandTimeout = 1500
Conn.Open sCo1, sCo2, sCo3
Set rs = Conn.Execute(MSql)			 



%>
<html>
<head>
<title><% = sTitle %></title>
<% = sBODY %>
<% = sCABECALHO %>VENDAS PNLD 2005<% = sFONT %></b>
  <table width='100%' border='1'<% =  sTABLE %>>
  <tr bgcolor='<% = COR_TARJA %>'>
  <td>Estado</td>
  <td>Editora</td>
  <td>Qtd</td>
  </tr><%
  mcnt=0
  GQTD=0
  GVAL=0
  
 Do while not rs.eof
   mUF=rs("UF")
   mUFF=rs("UF")
   tcnt=0
   tQTD=0
   tVAL=0
   Do while not rs.eof and mUF=mUFF
    tcnt=tcnt+1
    tQTD=tQTD+rs("QTD")
    mcnt=mcnt+1
    GQTD=GQTD+rs("QTD")
    GVAL=GVAL+rs("VALOR")
    %><td>&nbsp;<% = rs("UF") %></td>
    <td><% = rs("EDITORA") %></td>
    <td align='right'><% = FORMATNUMBER(rs("QTD"),0) %></td>
    </tr><%
    rs.MoveNext     	
    if not rs.eof then
       mUF=rs("UF")
    else
       mUF="zzzzzz"
    end if
    loop

	  %><tr>
	  <td COLSPAN='2'><B>&nbsp;Total do Estado ==</td>
	  <td align='right'><B><% = FORMATNUMBER(tQTD,0)  %></td>
   </tr><%

  loop

	  %><tr>
	  <td COLSPAN='2'><B>&nbsp;Total Geral de itens  ===</td>
	  <td align='right'><B><% = FORMATNUMBER(GQTD,0)  %></td>
   </tr><%
rs.Close : Set rs = Nothing
Conn.Close : Set conn = Nothing 

%>
